package main

import (
	"fmt"
	"io"
	"os"
)

type Log struct{
	Output io.Writer
}

func NewLog(output io.Writer)*Log{
	return &Log{
		Output: output,
	}
}

func (l *Log) Error (s string) {
	fmt.Fprint(l.Output,s)
}

func (l *Log) Warning (s string) {
	fmt.Fprint(l.Output,s)
}

func (l *Log) Info (s string) {
	fmt.Fprint(l.Output,s)
	
}

func main() {
    //输出在控制台
	logger := NewLog(os.Stdout)
	logger.Info("infofo\n")
	logger.Warning("warninging\n")
	logger.Error("erroror\n")

    //输出到文件中
	f,_:=os.OpenFile("app.log",os.O_APPEND|os.O_WRONLY|os.O_CREATE,0644)
    defer f.Close()
	fileLogger := NewLog(f)
	fileLogger.Info("infofo\n")
	fileLogger.Warning("warninging\n")
	fileLogger.Error("erroror\n")
}